﻿<UserControl x:Class="ChatRoom.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:ChatRoom.ViewModel"
    mc:Ignorable="d"
             Loaded="OnLoaded"
             d:DesignHeight="451" d:DesignWidth="523">

    <UserControl.Resources>
        <Style TargetType="Button">
            <Setter Property="Margin" Value="5"/>
        </Style>

        <Style TargetType="ListBox">
            <Setter Property="Margin" Value="5"/>
        </Style>

        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="5"/>
        </Style>

        <vm:Msg2AlignmentConverter x:Key="alignConverter"/>
        <vm:Msg2BackgroundConverter x:Key="backgrdConverter"/>

    </UserControl.Resources>

    <Grid Background="Wheat">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>

        <ListBox Grid.Row="0" Grid.Column="0" 
                 ItemsSource="{Binding Path=ChatMessages}"
                 SelectedItem="{Binding Path=CurrentItem,Mode=TwoWay}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="DarkGray" BorderThickness="2">
                        <StackPanel Orientation="Vertical" 
                                    Background="{Binding Converter={StaticResource backgrdConverter}}">
                            <TextBlock Text="{Binding Path=Time}" FontWeight="Black"
                                       Padding="5"/>
                            <TextBlock Padding="5">
                            <Run Text="{Binding Path=Source}"/> said:
                            <Run Text="{Binding Path=Content}"/>
                            </TextBlock>
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <TextBox Grid.Row="1" Grid.Column="0" Text="{Binding Path=TxtToSend,Mode=TwoWay}"/>

        <ListBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Path=ClientInfos}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock>
                        <Run Text="{Binding Path=Host}"/>:
                        <Run Text="{Binding Path=Port}"/>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <Button Grid.Row="1" Grid.Column="1" 
                MinWidth="150"
                Content="Send"
                Command="{Binding Path=CmdSendChat}"/>


    </Grid>
</UserControl>
